package com.baseDemo.web.dao.catalog.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.baseDemo.web.dao.catalog.CatalogEntityDao;
import com.baseDemo.web.entity.CatalogEntity;
import com.share.hibernate.baseDaoSupport.impl.BaseDaoHibernateSupport;
@Repository
public class CatalogEntityDaoHibernate extends BaseDaoHibernateSupport<CatalogEntity> implements CatalogEntityDao{
	private static Map<String, Object> paramMap = new HashMap<String, Object>();
	@Override
	public List<CatalogEntity> getChildrenByParent(String parentid,String userId) {
		String HQL = "from CatalogEntity ce where ce.userId = :userId and ce.parent.id = :parentid ";
		paramMap.clear();
		paramMap.put("userId", userId);
		paramMap.put("parentid", parentid);
		return super.find(HQL, paramMap);
	}

	@Override
	public String updateCatalogText(String id,String text) {
		String HQL = "update CatalogEntity ce set ce.text=:text where ce.id = :id";
		paramMap.clear();
		paramMap.put("text", text);
		paramMap.put("id", id);
		return super.execute(HQL, paramMap);
	}

	@Override
	public String updateCatalogParent(String id, String parentId) {
		String HQL = "update CatalogEntity ce set ce.parent.id=:parentId where ce.id = :id";
		paramMap.clear();
		paramMap.put("parentId", parentId);
		paramMap.put("id", id);
		return super.execute(HQL, paramMap);
	}

}
